package components.tools
{
	import UIFree.ObjectEvent;
	import UIFree.controls.uif_label;
	import UIFree.controls.uif_list;
	import UIFree.uif_component;
	
	import classes.c_events;
	
	import components.c_component;
	import components.c_window;
	
	import flash.events.Event;
	import flash.geom.Rectangle;
	
	public class c_layersWindow extends c_window {
		private var _listView	: uif_list;
		private var _list		: Array;
		public function c_layersWindow(parent:uif_component) {
			super(parent, 300, 400, locale.LAYERSTITLE, false, 1);
		}
		
		override protected function listenEvents():void {
			super.listenEvents();
			addEvent(c_events.SHOWLAYERSTOOLS, function(e: Event): void {
				show();
			}, cl.workspace);
			
			addEvent(c_events.ADDEDLAYER, doAddedLayer, cl.workspace)
		}
		
		override protected function createDialogComponents():void {
			super.createDialogComponents();
			var rect: Rectangle = clientBounds;
			var space: Number = getSpace();
			rect.top += space;
			_listView 	= new uif_list(this, rect.x, rect.y, rect.width, rect.height, 'list');
			_list		= new Array();
		}
		
		protected function doAddedLayer(e: ObjectEvent): void {
			_listView.attachList([{
				object	: e.object,
				name	: 'layer ' + _listView.listLength
			}], doCreateListItem);
		}
		
		protected function doCreateListItem(area: uif_component, itemData: Object, i: int): c_component {
			var item: c_layerItem = new c_layerItem(area, i * c_layerItem.HEIGHT, itemData);
			return item;
		}
	}
}